package cn.etynit.user.service.impl;

import cn.etynit.user.domain.Logininfo;
import cn.etynit.user.domain.User;
import cn.etynit.user.mapper.LogininfoMapper;
import cn.etynit.user.mapper.UserMapper;
import cn.etynit.user.service.IUserService;
import cn.etynit.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author etynit
 * @since 2022-10-19
 */



@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

    @Autowired
    private LogininfoMapper logininfoMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public void add(User user) {

        Logininfo logininfo = new Logininfo();
        logininfo.setId(user.getLogininfoId());
        logininfo.setUsername(user.getUsername());
        logininfo.setPhone(user.getPhone());
        logininfo.setEmail(user.getEmail());
        logininfo.setSalt(user.getSalt());
        logininfo.setSalt(user.getSalt());
        logininfo.setPassword(user.getPassword());
        logininfoMapper.add(logininfo);
        super.add(user);
    }

    /**
     * 通过logininfoId查询到user对象
     * @param id
     * @return
     */
    @Override
    public User findByLoginId(Long id) {
        return userMapper.findByLoginId(id);
    }
}
